local tonghao = fk.CreateSkill{
    name = "rmt__tonghao",
    tags = {Skill.Limited}
}
Fk:loadTranslationTable{
    ["rmt__tonghao"] = "姛好",
    [":rmt__tonghao"] = "限定技，轮次开始时，你可以从四个女性武将牌中选择不同角色的两个技能获得之，并于发动后失去，均失去后，你复原“姛好”，或永久获得上次失去的技能。",
    ["#rmt__tonghao-choice"] = "是否发动 姛好？选择并获得两个技能",
    ["#rmt__tonghao-prompt"] = "复原 姛好 ？或点“取消”永久获得 %arg",
}

tonghao:addEffect(fk.RoundStart, {
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(tonghao.name) and player:usedSkillTimes(tonghao.name,Player.HistoryGame) == 0
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local generals, skillList = {}, {}
        local index = 1
        while #generals < 4 and index <= #room.general_pile do
            local g = room.general_pile[index]
            if Fk.generals[g].gender == General.Female and Fk.generals[g].trueName ~= "lvbao" and Fk:canUseGeneral(g) then
                local skills = Fk.generals[g]:getSkillNameList(false)
                if #skills > 0 then
                    table.insert(generals, table.remove(room.general_pile, index))
                    table.insert(skillList, skills)
                else
                    index = index + 1
                end
            else
                index = index + 1
            end
        end
        local choice = {}
        if #generals == 0 then return false else choice = {skillList[1]} end
        if #generals > 0 then
            local result = room:askToCustomDialog(player,{
                skill_name = tonghao.name,
                qml_path = "packages/aaa_Romantic/qml/ChooseGeneralSkillsBox.qml",
                extra_data = {
                    generals, skillList, 2, 2, "#rmt__tonghao-choice", false
                }
            })
            room:returnToGeneralPile(generals, "bottom")
            if result ~= "" then
                choice = json.decode(result)
            end
            room:setPlayerMark(player,tonghao.name,choice)
            room:handleAddLoseSkills(player, table.concat(choice, "|"), nil)
        end
    end,
})

tonghao:addEffect(fk.AfterSkillEffect, {
    can_refresh = function (self, event, target, player, data)
        return target == player and table.contains(player:getTableMark(tonghao.name), data.skill:getSkeleton().name)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        room:removeTableMark(player, tonghao.name, data.skill:getSkeleton().name)
        room:handleAddLoseSkills(player, "-"..data.skill:getSkeleton().name, nil, true, false)

        if #player:getTableMark(tonghao.name) == 0 then
            if room:askToSkillInvoke(player,{
                skill_name = tonghao.name,
                prompt = "#rmt__tonghao-prompt:::"..data.skill:getSkeleton().name,
            }) then
                player:setSkillUseHistory(tonghao.name,0,Player.HistoryGame)
            else
                room:handleAddLoseSkills(player, data.skill:getSkeleton().name, nil, true, false)
            end
        end
    end,
})

return tonghao